package com.ctc.lottery.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.ctc.lottery.entity.Lottery;
import com.ctc.lottery.entity.Prize;
import com.ctc.lottery.service.*;
import com.ctc.utils.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 1、设置抽奖活动
 * 2、抽奖
 * @author ctc
 */
@Api(tags = "抽奖管理")
@RestController
@RequestMapping(value = "/lottery")
@Slf4j
public class LotteryController {

    @Autowired
    private CommodityService commodityService;
    @Autowired
    private IndentService indentService;
    @Autowired
    private MemberService memberService;
    @Autowired
    private PrizeService prizeService;
    @Autowired
    private LotteryService lotteryService;
    @Autowired
    private StringRedisTemplate redisTemplate;


    @ApiOperation(value = "查询参与抽奖商品")
    @GetMapping(value = "/getLotteryCommodity")
    public R getLotteryCommodity(String activityName) {
        List<Prize> prizeList = prizeService.list(
                new LambdaQueryWrapper<Prize>().eq(Prize::getActivityName,activityName)
        );

        return R.ok().put("data",prizeList);
    }

    @ApiOperation(value = "抽奖")
    @PostMapping(value = "/lottery")
    public R lottery(String activityName) {
        return lotteryService.lottery(activityName);
    }


    @ApiOperation(value = "查询所有抽奖活动")
    @GetMapping(value = "/getLottery")
    public R getLottery() {
        List<Lottery> lottery = lotteryService.list();

        return R.ok().put("data",lottery);
    }



}
